package com.fist.eth.flutter_plugin_eth_wallet.utils

import org.web3j.crypto.LinuxSecureRandom
import java.security.SecureRandom

object SecureRandomUtils {
    private val SECURE_RANDOM: SecureRandom
    private var isAndroid = -1

    init {
        if (isAndroidRuntime())
            LinuxSecureRandom()

        SECURE_RANDOM = SecureRandom()
    }

    val secureRandom: SecureRandom get() = SECURE_RANDOM

    fun isAndroidRuntime(): Boolean {
        if (isAndroid == -1) {
            val runtime = System.getProperty("java.runtime.name")
            isAndroid = if (runtime != null && runtime == "Android Runtime") 1 else 0
        }
        return isAndroid == 1
    }
}